﻿using Dapper;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TodoApp.TMS_Contract.Contracts;
using Volo.Abp.DependencyInjection;
using Volo.Abp.Domain.Repositories.Dapper;
using Volo.Abp.EntityFrameworkCore;

namespace TodoApp.EntityFrameworkCore
{
    public class DapperDbContrxtRepository : DapperRepository<TodoAppDbContext>, ITransientDependency
    {
        public DapperDbContrxtRepository(IDbContextProvider<TodoAppDbContext> dbContextProvider) : base(dbContextProvider)
        {

        }
        /// <summary>
        /// 显示查询
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="sql"></param>
        /// <param name="param"></param>
        /// <returns></returns>
        public async Task<List<T>> GetAllContracts<T>(string sql,object param)where T:class,new()
        {
            var dbConnection = await GetDbConnectionAsync();
            return (await dbConnection.QueryAsync<T>(sql, param: await GetDbTransactionAsync()))
                .ToList();
        }

        /// <summary>
        /// 增删改
        /// </summary>
        /// <param name="sql"></param>
        /// <param name="param"></param>
        /// <returns></returns>
        public async Task<int> UpdatePersonNames(string sql,object param)
        {

            var dbConnection = await GetDbConnectionAsync();
            return await dbConnection.ExecuteAsync(sql, param,
                 await GetDbTransactionAsync());

            //var dbConnection = await GetDbConnectionAsync();
            //return await dbConnection.ExecuteAsync("update TMS_Contracts set Contract_Title=@NewName", new { NameName = name }, await GetDbTransactionAsync());
        }
    }
}
